package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.CouponsMapper;
import com.ming.easyDevelop.entity.po.Coupons;
import com.ming.easyDevelop.entity.query.CouponsQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.CouponsService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import java.util.Date;
import java.math.BigDecimal;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("couponsService")
public class CouponsServiceImpl implements CouponsService {
	private final CouponsMapper<Coupons, CouponsQuery> couponsMapper;

	public CouponsServiceImpl(CouponsMapper couponsMapper){
		this.couponsMapper = couponsMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<Coupons> findListByParam(CouponsQuery query){
		return this.couponsMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(CouponsQuery query){
		return this.couponsMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<Coupons> findListByPage(CouponsQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<Coupons> res = this.findListByParam(query);
		return new PaginationResVo<Coupons>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<Coupons> list){
		return this.couponsMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(Coupons bean){
		return this.couponsMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(Coupons bean){
		return this.couponsMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<Coupons> list){
		return this.couponsMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据CouponCode查询
	 */
	@Override
	public Coupons getByCouponCode(String couponCode){
		return this.couponsMapper.selectByCouponCode(couponCode);
	}

	/**
	 * 根据CouponCode更新
	 */
	@Override
	public Long updateByCouponCode(Coupons bean, String couponCode){
		return this.couponsMapper.updateByCouponCode(bean,couponCode);
	}

	/**
	 * 根据CouponCode删除
	 */
	@Override
	public Long deleteByCouponCode(String couponCode){
		return this.couponsMapper.deleteByCouponCode(couponCode);
	}

}
